// import AsyncStorage from '@react-native-community/async-storage';
import list from '../../component/home/data.json';
import {api, http} from '../../http';
const getLayoutData = async () => {
  // return await http.get(api.HOME_POSITION_LAYOUT, {id: 4});
  return await new Promise(resole => {
    setTimeout(() => {
      resole({modules: list});
    }, 3000);
  });
};

export default {
  namespace: 'home',
  state: {
    layoutData: [],
    isNoData: false,
  },
  // action 返回一个Promise
  effects: {
    *layoutInit({payload: todo}, {put, call, select}) {
      const result = yield call(getLayoutData);
      if (result && result.modules) {
        yield put({type: 'setLayoutData', payload: result.modules});
      } else {
        yield put({type: 'setNoData', payload: true});
      }
    },
  },
  reducers: {
    /**
     * @des 没有数据
     */
    setNoData(data, res) {
      data.isNoData = res.payload;
      return data;
    },
    setLayoutData(data, res) {
      data.layoutData = res.payload;
      return data;
    },
  },
  // 初始化数据，订阅一个数据源， 并派发 {history} = undefined
  subscriptions: {},
};
